<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\common\command;


use app\common\model\bookpack\BookpackAssociation;
use app\common\model\task\UserTask as UserTaskModel;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;


class UpdateBookpack extends Command
{
    protected function configure()
    {
        $this->setName('update_bookpack')
            ->setDescription('更新推广书包');
    }


    protected function execute(Input $input, Output $output)
    {
        try {
//            UserTaskModel::where(1,1)->update($data);
            $backpack = [9,10,11,12,13];
            $book_id_arr = [3450,3474,3476,3477,3325,3341,3479,3480,3481,3482,1462,3306,3311,3314,3321,3325,3167,3327,3332,3334,3338,3341,3345,3352,3354,3357,3359];
            $arrAll = [];
            foreach ($backpack as $k=>$v){
                foreach ($book_id_arr as $kk=>$vv){
                    $arr['bookpack_id'] = $v;
                    $arr['book_id'] = $vv;
                    $arrAll[] = $arr;
                }
            }
            foreach ($arrAll as $item){
                $bookpackAssociation = BookpackAssociation::where(['book_id'=>$item['book_id'],'bookpack_id'=>$item['bookpack_id']])->findOrEmpty();
                if ($bookpackAssociation->isEmpty()){
                    BookpackAssociation::create(['book_id'=>$item['book_id'],'bookpack_id'=>$item['bookpack_id']]);
                }else{
                    echo "重复";
                }
            }
            $output->writeln('update_bookpack');
            return true;
        } catch (\Exception $e) {
            Log::write('用户任务重置失败,失败原因:' . $e->getMessage());
            return false;
        }
    }

}